package controllers

import play.api.libs.json.Json

import javax.inject._
import play.api.mvc._

/**
 * This controller creates an `Action` to handle HTTP requests to the
 * application's home page.
 */
@Singleton
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {

  /**
   * Create an Action to render an HTML page with a welcome message.
   * The configuration in the `routes` file means that this method
   * will be called when the application receives a `GET` request with
   * a path of `/`.
   */
  def index = Action {implicit request=>

    Ok(views.html.home.indexPage())
  }

  def blankPage(title: String) = Action {implicit request=>
    Ok(views.html.blank.blankPage(title))
  }

  def banner = Action {implicit request=>
    Ok(views.html.home.components.banner())
  }

  def changeLanguage = Action{implicit request=>
    val href = request.headers.get("Referer").get
    val lang = request.session.get("lang")
    val l = if(lang == Option("cn")) "en" else "cn"
    Redirect(href).withSession("lang" -> l)
  }

}
